package com.jt.web.controller;

import com.fasterxml.jackson.databind.util.JSONPObject;
import com.jt.pojo.CatResult;
import com.jt.pojo.SearchResult;
import com.jt.service.ItemCatService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

/**
 *
 * @author dc
 * @Classname WebItemCatController
 * @Date 2020/3/23 14:33
 */
@RestController
@RequestMapping("/web/itemcat")
public class WebItemCatController {

    @Autowired
    private ItemCatService itemCatService;

    /**
     * 商城首页分类目录(Jsonp查询)
     * @param callback 回调函数名
     * @return
     */
    @RequestMapping("/all")
    public JSONPObject getItemCatList(String callback){
        CatResult itemCatList = itemCatService.findItemCatList();
        return new JSONPObject(callback,itemCatList);
    }

    @RequestMapping("/findItemsByCatId")
    public SearchResult findItemsByCatId(Long itemCatId, Integer page, Integer rows){
        return itemCatService.findItemsByCatId(itemCatId, page, rows);
    }

    @RequestMapping("/findItemName")
    public String findItemNameByCatId(Integer itemCatId){
        return itemCatService.findItemCatById(itemCatId);
    }
}
